﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Linq.Expressions;

namespace MoneyManagerNET.Presentation.Infrastructure.Binding
{
    public class ValidatableWrapper : DynamicNotifyableWrapper, IDataErrorInfo
    {
        public ValidatableWrapper(object instance):base(instance)
        {

        }
        
        public string Error
        {
            get { return string.Join(" ; ", _Errors.Values.Cast<string>().ToArray()); }
        }

        Dictionary<string, string> _Errors = new Dictionary<string, string>();
        public string this[string columnName]
        {
            get { return _Errors[columnName]; }
        }

        protected string this[Expression<Func<object>> property]
        {
            set
            {
                var propName = BindingExtensions.Expression2PropertyName(property);
                _Errors[propName] = value;
                this.OnChange(() => Error);
            }
        }
    }
}
